﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class new_Default : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strPage = Request["page"];
            int page = 1;
            try
            {
                page = int.Parse(strPage);
                if (page < 1)
                {
                    page = 1;
                }
            }
            catch (Exception ex)
            {
                page = 1;
            }
            bd(page);
        }
    }

    public int GetPage()
    {
        return AspNetPager1.CurrentPageIndex;
    }

    private void bd(int page)
    {
        int tid =int.Parse( Request["tid"]);
        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
        var data = from a in dal.Topics2News
                   from b in dal.News
                   from c in dal.Topics2Title
                   where a.NewsId == b.id && a.TitleId==c.Id && c.Tid==tid
                   select new { b.id,aid=a.Id, b.title, b.ctime, b.ptime, b.Stock, b.IsEnable, b.step,type=c.Title,tid=c.Tid,titleId=c.Id };
        AspNetPager1.RecordCount = data.Count();
        AspNetPager1.CurrentPageIndex = page;
        data = data.OrderByDescending(x => x.ctime).Skip((page - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize);
        Repeater1.DataSource = data;
        Repeater1.DataBind();
    }


    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bd(AspNetPager1.CurrentPageIndex);
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {

    }
}